package com.onenine.app.view.popwin;

import android.app.Activity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;

import com.onenine.app.R;
import com.onenine.app.adapter.BarrageCateAdapter;
import com.onenine.app.model.BarrageItem;
import com.onenine.common.util.ApUtils;

import java.util.ArrayList;
import java.util.List;

public class BarrageListPopWindow extends BottomPopWindow {

    private RecyclerView mRvList;
    private List<BarrageItem> mBarrageList;

    public BarrageListPopWindow(Activity activity, List<BarrageItem> barrageList, BarrageItem currentBarrage) {
        super(activity);
        mBarrageList = barrageList;
        getBarrageTypeList(currentBarrage);
    }

    @Override
    protected View genContentView() {
        mRvList = (RecyclerView) LayoutInflater.from(ApUtils.getApp())
                .inflate(R.layout.layout_recycler_view, null, false);
        mRvList.setLayoutManager(new LinearLayoutManager(ApUtils.getApp()
                , LinearLayoutManager.HORIZONTAL, false));
        return mRvList;
    }

    /**
     * 获取弹幕同类型数据
     */
    private void getBarrageTypeList(BarrageItem currentBarrage) {
        if (mBarrageList == null) {
            return;
        }
        List<BarrageItem> resultList = new ArrayList<>();
        for (BarrageItem item : mBarrageList) {
            if (TextUtils.equals(item.getPkId(), currentBarrage.getPkId())) {
                resultList.add(0, item);
            } else if (item.getBarrageType() == currentBarrage.getBarrageType()) {
                resultList.add(item);
            }
        }
        mRvList.setAdapter(new BarrageCateAdapter(mActivity, resultList));
    }

}
